package com.frog.framework.s3.config;

import com.frog.framework.s3.factory.S3EndpointFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.SmartInitializingSingleton;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;

/**
 * @author wuqiong 2022/10/27
 * @description
 */
public class S3AnnotationBeanPostProcessor implements BeanFactoryPostProcessor, SmartInitializingSingleton {
    private static final Logger logger = LoggerFactory.getLogger(S3AnnotationBeanPostProcessor.class);

    private ConfigurableListableBeanFactory configurableListableBeanFactory;


    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
        this.configurableListableBeanFactory = beanFactory;
    }

    @Override
    public void afterSingletonsInstantiated() {
        logger.info("S3AnnotationBeanPostProcessor create s3 client ......... ");
        S3EndpointFactory.createBatchByConfig(configurableListableBeanFactory.getBean(S3Config.class));
    }
}
